package com.gitee.helioz.openai.api.endpoint.models;

import com.gitee.helioz.openai.api.OpenAiService;
import com.gitee.helioz.openai.api.dto.models.ModelDTO;
import com.gitee.helioz.openai.api.dto.models.ModelListResponse;
import com.gitee.helioz.openai.common.constants.OpenAiApiUrl;
import com.gitee.helioz.openai.common.error.OpenAiErrorException;
import com.gitee.helioz.openai.common.util.json.GsonUtil;
import lombok.RequiredArgsConstructor;

/**
 * 〈模型服务〉
 *
 * @author <a href="https://gitee.com/helioz">Morning Starr</a>
 */
@RequiredArgsConstructor
public class ModelsServiceImpl implements ModelsService {
    private final OpenAiService openAiService;

    @Override
    public ModelListResponse list() {
        String responseStr = openAiService.get(OpenAiApiUrl.Models.LIST.getUrl(openAiService.getApiHost()));
        return GsonUtil.fromJson(responseStr, ModelListResponse.class);
    }

    @Override
    public ModelDTO retrieve(String modelId) {
        String url = OpenAiApiUrl.Models.RETRIEVE.getUrl(openAiService.getApiHost()) + modelId;
        String responseStr = openAiService.get(url);
        return GsonUtil.fromJson(responseStr, ModelDTO.class);
    }
}
